package com.example.exampleviewpager.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.exampleviewpager.R;
import com.example.exampleviewpager.ui.adapter.MyPagerAdapter;

import java.util.ArrayList;

public class MainActivity2 extends AppCompatActivity {

    private ViewPager mVpMain2;
    private ArrayList<View> arrayList=new ArrayList<>();
    private String[] titles={"孙伟豪1","孙伟豪2","孙伟豪3","孙伟豪4","孙伟豪5"};
    private int[] images={R.drawable.yd1,R.drawable.yd2,R.drawable.yd3,R.drawable.yd4,R.drawable.yd5};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        for (int i = 0; i < titles.length; i++) {
            View view= View.inflate(MainActivity2.this,R.layout.item_vp_view,null);
            arrayList.add(view);
        }
        MyPagerAdapter myPagerAdapter=new MyPagerAdapter(MainActivity2.this);
        myPagerAdapter.setData(arrayList,titles,images);
        mVpMain2.setAdapter(myPagerAdapter);
    }

    private void initView() {
        mVpMain2 = (ViewPager) findViewById(R.id.vp_main2);
    }
}